package top.heathylife.gateway.common.po;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.annotation.JSONField;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.List;

/**
 * 接口的参数说明
 * @author maoxiaomeng
 */
@Data
@Accessors(chain = true)
@ApiModel(value = "一个基础接口的参数数据")
public class ApiParameterPo implements Serializable {
    private static final long serialVersionUID = -3636703657738690902L;
    @ApiModelProperty(required = true, value = "接口参数名")
    String key;
    @ApiModelProperty(required = true, value = "接口的参数全路径名,包含了接口所在类的层级,\".\"号分割")
    String absoluteKey;
    @ApiModelProperty(required = true, value = "参数说明")
    String info;
    @ApiModelProperty(required = true, value = "示例值")
    String example;
    @ApiModelProperty(required = true, value = "扩展字段字段说明")
    String extend;
    @ApiModelProperty(required = true, value = "是否必须填写")
    Boolean necessary;
    @JSONField(serialize = false)
    @ApiModelProperty(required = true, value = "数据类型")
    Class<?> type;
    @ApiModelProperty(required = true, value = "数据类型")
    String typeName;
    @ApiModelProperty(required = true, value = "历史查询记录")
    List<Object> historyInput;
    @ApiModelProperty(required = true, value = "其它所有的参数")
    List<ApiParameterPo> list;

    public String getTypeName() {
        //fixme 检查下 为什么 type会没值
        if(!ObjectUtil.isEmpty(typeName)){
            return this.typeName;
        }
        if (type == null) {
            return null;
        }
        return type.getSimpleName();
    }
}
